package main

import (
	"fmt"
	"time"
)

//有缓存的channel channel为满 向里面写数据会阻塞  channel为空向里面拿数据会阻塞
func main() {

	c := make(chan int, 3) //创建带有缓冲的channel

	fmt.Println("lne(c) = ", len(c), "cap(c) = ", cap(c))

	go func() {
		defer fmt.Println("子go程结束")

		for i := 0; i < 3; i++ {
			c <- i
			fmt.Println("子go程正在运行,发送的元素= ", i, " len(c) = ", len(c), " cap(c) = ", cap(c))
		}
	}()

	time.Sleep(2 * time.Second)

	for i := 0; i < 3; i++ {
		num := <-c
		fmt.Println("num = ", num)
	}
}
